package com.txhy.certificatechain.presenter.pay;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.txhy.certificatechain.api.UrlAddress;
import com.txhy.certificatechain.presenter.base.BasePresenter;
import com.txhy.certificatechain.ui.view.pay.ScannerView;
import com.txhy.certificatechain.utils.GsonUtil;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2018-2030, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * 文    件: ScannerPresenter.java
 * 作    者: 侯建军
 * 版    权: 1.0.0
 * 描    述: 扫一扫
 * 创建时间: 2018/9/21 10:45
 * 更新时间：2018/9/21 10:45
 * -----------------------------------------------------------------
 * 2018/9/21 10:45: 创建 ScannerPresenter.java (侯建军);
 * -----------------------------------------------------------------
 */
public class ScannerPresenter extends BasePresenter<ScannerView> {
    public void webLogin(String code ,String userId,String userType) {
        OkGo.<String>post(UrlAddress.LOGIN_URL)//
                .tag(this)//
                .params("code", code )
                .params("userId", userId )
                .params("userType", userType )
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (GsonUtil.GsonGetStatus(response.body()) == 200) {
                            getView().webLoginSuccess(GsonUtil.GsonGetMsg(response.body()));
                        } else {
                            getView().webLoginFail(GsonUtil.GsonGetMsg(response.body()));
                        }
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        getView().webLoginFail("请求失败请检查网络");
                    }
                });
    }
}

